package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyUserMonthCardVo;
import com.ruoyi.system.bo.ZsyyUserMonthCardQueryBo;
import com.ruoyi.system.bo.ZsyyUserMonthCardAddBo;
import com.ruoyi.system.bo.ZsyyUserMonthCardEditBo;
import com.ruoyi.system.service.IZsyyUserMonthCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 月卡管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "月卡管理控制器", tags = {"月卡管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/userMonthCard")
public class ZsyyUserMonthCardController extends BaseController {

    private final IZsyyUserMonthCardService iZsyyUserMonthCardService;

    /**
     * 查询月卡管理列表
     */
    @ApiOperation("查询月卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyUserMonthCardVo> list(@Validated ZsyyUserMonthCardQueryBo bo) {
        return iZsyyUserMonthCardService.queryPageList(bo);
    }

    /**
     * 导出月卡管理列表
     */
    @ApiOperation("导出月卡管理列表")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:export')")
    @Log(title = "月卡管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyUserMonthCardVo> export(@Validated ZsyyUserMonthCardQueryBo bo) {
        List<ZsyyUserMonthCardVo> list = iZsyyUserMonthCardService.queryList(bo);
        ExcelUtil<ZsyyUserMonthCardVo> util = new ExcelUtil<ZsyyUserMonthCardVo>(ZsyyUserMonthCardVo.class);
        return util.exportExcel(list, "月卡管理");
    }

    /**
     * 获取月卡管理详细信息
     */
    @ApiOperation("获取月卡管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyUserMonthCardVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyUserMonthCardService.queryById(id));
    }

    /**
     * 新增月卡管理
     */
    @ApiOperation("新增月卡管理")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:add')")
    @Log(title = "月卡管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyUserMonthCardAddBo bo) {
        return toAjax(iZsyyUserMonthCardService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改月卡管理
     */
    @ApiOperation("修改月卡管理")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:edit')")
    @Log(title = "月卡管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyUserMonthCardEditBo bo) {
        return toAjax(iZsyyUserMonthCardService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除月卡管理
     */
    @ApiOperation("删除月卡管理")
    @PreAuthorize("@ss.hasPermi('system:userMonthCard:remove')")
    @Log(title = "月卡管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyUserMonthCardService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
